﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ElectronicCommerce.Framework.ServiceModel.WCF
{
    /// <summary>
    /// http://www.rainsts.net/article.asp?id=444
    /// </summary>
    public class WCFServiceBroker : ServiceBrokerBase, IServiceBroker, IServiceProvider
    {
        private static IServiceBroker serviceBroker = new WCFServiceBroker();

        private WCFServiceBroker() { }

        /// <summary>
        /// 
        /// </summary>
        public static IServiceBroker Instance
        {
            get
            {
                return serviceBroker;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="serviceName"></param>
        /// <returns></returns>
        public override T DoGetService<T>(string serviceName)
        {
            T serviceChangel = default(T);
            ClientServiceProxy<T> serviceProxy = new ClientServiceProxy<T>(serviceName);
            serviceChangel = serviceProxy.Channel;
            return serviceChangel;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="serviceType"></param>
        /// <param name="serviceName"></param>
        /// <returns></returns>
        public override object DoGetService(Type serviceType, string serviceName)
        {
            throw new NotSupportedException();
        }
    }
}
